package com.atguigu.gulimall.product.util;

import com.alibaba.nacos.common.utils.StringUtils;
import org.apache.http.HttpRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @Author learner
 * @Create 2023/12/22 10:17
 * @Version 1.0
 */
public class HttpRequestUtil {
    
    public HttpServletRequest get() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest httpServletRequest = null;
        if (requestAttributes != null) {
            httpServletRequest = requestAttributes.getRequest();
            Objects.requireNonNull(httpServletRequest, "The http request is null!");
        }
        return httpServletRequest;
    }
    
    public void  test() {
        HttpServletRequest httpServletRequest = get();
        String accessToken = httpServletRequest.getHeader("AccessToken");
        
    }
}
